"""
读取二进制文件
- 复制图片

Version: 0.1
Author: yuwl
Date：2024-4-07
"""

import base64

def main():
    try:
        with open('icons.png', 'rb') as fsi:
            data = fsi.read()
            print(type(data))
            print('字节数：', len(data))
            # 将图片base64编码
            print(base64.b64encode(data))
        with open('icons_copy.png', 'wb') as fso:
            fso.write(data)
    except FileNotFoundError as e:
        print(f'指定的文件无法打开：{e}')
    except IOError as e:
        print(f'读写文件时出现错误：{e}')
    print('程序执行结束')

if __name__ == '__main__':
    main()